{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Auto Demand Organizer Test\n",
    "\n",
    "This notebook tests the `AutoDemandOrganizer` class from `auto_demand_organizer.py`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Import required modules\n",
    "import os\n",
    "import byzerllm\n",
    "from autocoder.agent.auto_demand_organizer import AutoDemandOrganizer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\u001b[32m2024-12-27 11:15:18.679\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36mbyzerllm.utils.connect_ray\u001b[0m:\u001b[36mconnect_cluster\u001b[0m:\u001b[36m48\u001b[0m - \u001b[1mJDK 21 will be used (/Users/allwefantasy/.auto-coder/jdk-21.0.2.jdk/Contents/Home)...\u001b[0m\n",
      "2024-12-27 11:15:18,745\tINFO worker.py:1564 -- Connecting to existing Ray cluster at address: 127.0.0.1:6379...\n",
      "2024-12-27 11:15:18,763\tINFO worker.py:1740 -- Connected to Ray cluster. View the dashboard at \u001b[1m\u001b[32m127.0.0.1:8265 \u001b[39m\u001b[22m\n"
     ]
    }
   ],
   "source": [
    "# Initialize LLM\n",
    "llm = byzerllm.ByzerLLM.from_default_model(model=\"deepseek_chat\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Initialize AutoDemandOrganizer\n",
    "project_dir = \"/Users/allwefantasy/projects/auto-coder\"\n",
    "organizer = AutoDemandOrganizer(llm=llm, project_dir=project_dir,skip_diff=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Organized Demands:\n",
      "\n",
      "Group: auto_demand_organizer.py 相关变更\n",
      "\n",
      "Type: Update\n",
      "Description: 根据 auto_demand_organizer.py 的输出变化修改 test_auto_demand_organizer.ipynb\n",
      "Reason: 确保测试文件与主逻辑文件输出一致\n",
      "\n",
      "Type: Update\n",
      "Description: OrganizedDemands 新增组名，同步修改 organize_demands 函数输出\n",
      "Reason: 支持需求分组功能\n",
      "\n",
      "Type: New\n",
      "Description: 参考 test_auto_guess_query.ipynb 新实现一个 jupyter notebook 对 auto_demand_organizer.py 进行测试\n",
      "Reason: 增加测试覆盖率\n",
      "\n",
      "Group: auto_guess_query.py 相关变更\n",
      "\n",
      "Type: Update\n",
      "Description: predict_next_task 接收可选参数 task_limit_size，传递给 guess_next_query\n",
      "Reason: 增加任务预测的灵活性\n",
      "\n",
      "Type: Update\n",
      "Description: predict_next_task 改为 predict_next_tasks，返回一组可选 NextQuery\n",
      "Reason: 支持多任务预测\n",
      "\n",
      "Type: Update\n",
      "Description: guess_next_query 返回 json 数组，并给定示例\n",
      "Reason: 优化返回格式\n",
      "\n",
      "Type: New\n",
      "Description: 参考 test_auto_filegroup.ipynb 生成对 auto_guess_query.py 的 jupyter notebook\n",
      "Reason: 增加测试覆盖率\n",
      "\n",
      "Group: auto_filegroup.py 相关变更\n",
      "\n",
      "Type: Update\n",
      "Description: 优化 group_by_similarity 方法\n",
      "Reason: 提升分组逻辑的准确性\n",
      "\n",
      "Type: Update\n",
      "Description: 修改 AutoFileGroup 的初始化参数和 group_by_similarity 方法，增加 file_size_limit 限制\n",
      "Reason: 支持文件大小限制\n",
      "\n",
      "Type: Update\n",
      "Description: 重构分组逻辑，给定一组 yaml 文件，得到里面的 query 和 urls，一起给到一个分组 prompt 函数\n",
      "Reason: 优化分组逻辑\n",
      "\n",
      "Type: New\n",
      "Description: 在 notebooks/tests 里新建一个 jupyter notebook，测试 auto_filegroup.py 中的分组功能\n",
      "Reason: 增加测试覆盖率\n",
      "\n",
      "Group: auto_coder_rag.py 相关变更\n",
      "\n",
      "Type: Update\n",
      "Description: 添加可选 query 参数，默认值为 'Hello, how are you?'\n",
      "Reason: 提供默认查询参数\n",
      "\n",
      "Type: Update\n",
      "Description: 添加新参数，支持按设置的并发控制跑多少轮，同步更新文档\n",
      "Reason: 支持并发控制\n",
      "\n",
      "Type: New\n",
      "Description: 在 docs 里添加一个 benchmark 的文档，通俗易懂，详细说明操作步骤\n",
      "Reason: 提供详细的文档说明\n",
      "\n",
      "Type: Update\n",
      "Description: 根据 token_limiter.py 的使用方式，修改 chunk_validation.py 中的 result 处理\n",
      "Reason: 优化结果处理逻辑\n",
      "\n",
      "Group: git_utils.py 相关变更\n",
      "\n",
      "Type: Update\n",
      "Description: 修复 get_last_yaml_file 中获取旧文件序号的逻辑错误\n",
      "Reason: 修复逻辑错误\n",
      "\n",
      "Type: Update\n",
      "Description: 修改文件名序列生成逻辑，使用 12 位数字序列并支持带下划线的文件名格式\n",
      "Reason: 优化文件名生成逻辑\n",
      "\n",
      "Type: Update\n",
      "Description: 移除 commit 函数中多余的 print 语句\n",
      "Reason: 清理冗余代码\n",
      "\n",
      "Type: New\n",
      "Description: 新增方法，获取当前项目还没有 commit 的信息，包括新增、删除以及修改文件列表，每个文件的差异，返回易于阅读的 markdown 字符串\n",
      "Reason: 提供更清晰的 commit 信息\n",
      "\n",
      "Group: coder.py 相关变更\n",
      "\n",
      "Type: Update\n",
      "Description: 改造 coder.py，提供一个新的 _run_task_in_terminal 实现，实时返回执行流程信息\n",
      "Reason: 优化终端交互体验\n",
      "\n",
      "Type: New\n",
      "Description: 创建一个 jupyter notebook，测试 coder.py，启动一个创建 reactjs + typescript + tailwindcss 的任务\n",
      "Reason: 增加测试覆盖率\n",
      "\n",
      "Type: Update\n",
      "Description: 优化 detect_env，给 EnvInfo 增加 default_shell, home_dir, cwd 三个新属性\n",
      "Reason: 提供更全面的环境信息\n",
      "\n",
      "Type: New\n",
      "Description: 针对 parse_assistant_message 生成一个 jupyter notebook，在 notebooks/tests 里\n",
      "Reason: 增加测试覆盖率\n",
      "\n",
      "Group: 其他变更\n",
      "\n",
      "Type: Update\n",
      "Description: 修改 commit_desc 描述，明确是基于用户人工修改的代码自动生成 yaml 文件并提交更改\n",
      "Reason: 提供更清晰的 commit 描述\n",
      "\n",
      "Type: New\n",
      "Description: 新增 /commit 命令，自动生成 yaml 文件并提交更改\n",
      "Reason: 简化提交流程\n",
      "\n",
      "Type: Update\n",
      "Description: 在 src/autocoder 目录下多个文件中添加了新的 import 和代码逻辑，以支持新的功能需求\n",
      "Reason: 支持新功能\n",
      "\n",
      "Type: New\n",
      "Description: 新增一个 rag_ 系列参数，叫 rag_params_max_tokens，默认值为 4096\n",
      "Reason: 支持最大 token 限制\n"
     ]
    }
   ],
   "source": [
    "organized_demands_list = organizer.organize()\n",
    "\n",
    "if organized_demands_list:\n",
    "    print(\"Organized Demands:\")\n",
    "    for organized_demands in organized_demands_list:\n",
    "        print(f\"\\nGroup: {organized_demands.group_name}\")\n",
    "        for demand in organized_demands.demands:\n",
    "            print(f\"\\nType: {demand.type}\")\n",
    "            print(f\"Description: {demand.description}\")\n",
    "            if demand.reason:\n",
    "                print(f\"Reason: {demand.reason}\")\n",
    "else:\n",
    "    print(\"Failed to organize demands\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Clean up test files\n",
    "import shutil\n",
    "shutil.rmtree(project_dir)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "byzerllm",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
